######
FROM ubuntu:16.04
MAINTAINER sppsorrg@gmail.com


RUN sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list &&\
    sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list &&\
    apt-get update && \
	apt-get install -y perl &&\
	apt-get install -y git &&\
	apt-get install -y exuberant-ctags &&\    	
    	apt-get install -y apache2 &&\
	apt-get install -y libapache2-mod-perl2 &&\
	apt-get install -y libmysqlclient-dev &&\
	apt-get install -y gcc &&\
	apt-get install -y make &&\
	apt-get install -y flex &&\
	apt-get install -y expect &&\
     cpan &&\
     sed -i.bak s!www.cpan.org!mirrors.163.com/cpan!g /root/.cpan/CPAN/MyConfig.pm &&\
     cpan DBI &&\
     cpan File::MMagic &&\
     cpan DBD::mysql

WORKDIR /glimpse
RUN git clone https://gitee.com/lengqinjie/glimpse.git &&\
cd glimpse &&\
./configure &&\
make &&\
make install

WORKDIR /
RUN git clone https://gitee.com/lengqinjie/lxr.git	

WORKDIR /lxr
ADD custom.d /lxr/custom.d
ADD scripts/expect_initdb /lxr/expect_initdb
ADD custom.d/lxr.conf /lxr
ADD .htaccess /lxr/.htaccess 
ADD ssl /etc/apache2/ssl

RUN ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/000-default-ssl.conf

RUN sed -i.bak 's/SSLCertificateFile.*.pem/SSLCertificateFile   \/etc\/apache2\/ssl\/lengqinjie.xyz.crt/g' /etc/apache2/sites-available/default-ssl.conf &&\
    sed -i.bak 's/SSLCertificateKeyFile.*.key/SSLCertificateKeyFile   \/etc\/apache2\/ssl\/lengqinjie.xyz.key/g' /etc/apache2/sites-available/default-ssl.conf &&\
    sed -i.bak '/SSLCertificateKeyFile.*.key/a\        SSLCertificateChainFile   \/etc\/apache2\/ssl\/root_bundle.crt' /etc/apache2/sites-available/default-ssl.conf &&\
    sed -i.bak '/<\/VirtualHost>/i\ \nRewriteEngine on\nRewriteCond   %{HTTPS} !=on\nRewriteRule   ^(.*)  https:\/\/%{SERVER_NAME}$1 [L,R]\n'  /etc/apache2/sites-available/000-default.conf

EXPOSE 2000

COPY scripts/entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

CMD ["/bin/bash"]
